package enumdemo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 常量类
 *
 * 这种定义方法不好
 * 因为数字有可能是简单的数字也可能是定义的常量
 */
public class Constant {
    public static final int RED = 1;
    public static final int WHITE = 1;
    public static final int GREEN = 1;

    //通过反射  不能创建枚举对象
    public static void main(String[] args) {

        Class<?> c;
        try {
            c = Class.forName("enumdemo.TestEnum");

            Constructor<?> constructor
                    //                      前两个参数是按照父类的方式传递的
                    = c.getDeclaredConstructor(String.class,int.class,int.class, String.class);

            constructor.setAccessible(true);
            TestEnum testEnum = (TestEnum) constructor.newInstance("ceshi",999,99, "HELLO");

            System.out.println(testEnum);

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
